<template>
  <div class="employee-container">
    <div style="background: #faf0e6;opacity: .8;margin-top:-10px;height: 30px">
    <el-row>
      <el-breadcrumb separator-class="el-icon-arrow-right">
        <el-breadcrumb-item :to="{ path: '../shouYe' } "style="margin-top: 5px;margin-left: 30px;">首页
        </el-breadcrumb-item>
        <el-breadcrumb-item style="margin-top: 5px;" >
          <i class="fa fa-server" aria-hidden="true"></i>
          基础信息管理
        </el-breadcrumb-item>
        <el-breadcrumb-item  style="margin-top: 5px;">
          <i class="fa fa-book" aria-hidden="true"></i>
          数据字典
        </el-breadcrumb-item>
      </el-breadcrumb>
    </el-row>
    </div>

    <el-row>
      <el-form label-width="80px">
        <el-row>
          <el-col :span="8" style="margin-top: 10px">
            <el-form-item label="字典项目" label-width="80px">
              <el-input style="height: 8%"/>
            </el-form-item>
          </el-col>
          <el-col :span="8" style="margin-top: 10px">
            <el-form-item label="所属类别" label-width="90px">
              <el-input></el-input>
            </el-form-item>
          </el-col>
          <el-col :span="8" style="margin-top: 10px">
            <el-form-item>
              <el-button type="success" style="background-color: cornflowerblue">
                <i class="fa fa-search" aria-hidden="true"></i>
                搜索Search
              </el-button>
            </el-form-item>
          </el-col>
        </el-row>
      </el-form>
    </el-row>
    <el-row>
      <div>
        <el-button-group>
          <el-button @click="btnAddClick" type="primary" icon="el-ico-edit" style="text-align: center">添加</el-button>
          <el-button type="warning" icon="el-icon-share">修改</el-button>
          <el-button   type="danger" icon="el-icon-delete">删除</el-button>
        </el-button-group>
      </div>
      <el-table :data="tableData"
                border
                stripe
                @row-dblclick="handleDoubleClick"
                style="width :100%">

        <i class="fa fa-map-marker" aria-hidden="true"> </i>
        <el-table-column

          prop="id"
          label="编码值"
          width="180"
          sortable
        >  </el-table-column>

        <el-table-column
          prop="display"
          label="显示值"
        ></el-table-column>
        <el-table-column
          prop="type"
          label="所属类别"
        ></el-table-column>
        <el-table-column
          prop="desc"
          label="备注信息"
        ></el-table-column>
      </el-table>

      <el-button-group>
        <el-button type="primary" icon="el-icon-arrow-left">上一页</el-button>

        <el-button type="primary">下一页<i class="el-icon-arrow-right el-icon--right"></i></el-button>
      </el-button-group>

    </el-row>

    <el-dialog
      :title="info.title"
      :visible.sync="dialogVisible"
      width="30%"
      :before-close="handleClose">
      <el-form>
        <el-form-group>
          <el-form-item label-width="80px" label="编码">
            <el-input v-model="dataDict.id"/>
          </el-form-item>
        </el-form-group>
        <el-form-group>
          <el-form-item label-width="80px" label="显示值">
            <el-input v-model="dataDict.display"/>
          </el-form-item>
        </el-form-group>
        <el-form-group>
          <el-form-item label-width="80px" label="所属类型">
         <!--  <el-input v-model="dataDict.type"/>-->
            <el-select  v-model="dataDict.type"  clearable placeholder="请选择" style="width: 280px">
              <el-option
                v-for="item in dataDict.options"
                :key="item.value"
                :label="item.label"
                :value="item.label">
              </el-option>
            </el-select>
          </el-form-item>
        </el-form-group>
        <el-form-group>
          <el-form-item label-width="80px" label="备注">
            <el-input v-model="dataDict.desc"/>
          </el-form-item>
        </el-form-group>
      </el-form>
      <span slot="footer" class="dialog-footer">
         <el-button type="primary" @click="sumbmitHandle">确定</el-button>
          <el-button @click="dialogVisible = false">取消</el-button>
      </span>
    </el-dialog>
  </div>
</template>

<script>
  export default{

    name: "dataDict", data(){
      return {
        tableData: [],
        gridData:[],
        info:{
          title:'数据添加'
        },
        dialogVisible: false,
        dialogFormVisible: false,
        formLabelWidth: '120px',

        dataDict: {
          id1: -1,
          id:'',
          display: '',
          type: '',
          desc: '',
          options: [{
            value: '选项1',
            label: 'city'
          }, {
            value: '选项2',
            label: 'packType'
          }],
          value: ''
        }


      }
    },mounted() {
      /*挂载结束之后*/
      var _this=this;
      this.axios({
        url:'http://localhost:3000/dataDict/list',
        method:'get'
      }).then(function (res) {
        _this.tableData=res.data;
      })
    },methods:{
      btnAddClick(){
        this.info.title='数据添加';
        this.dataDict.id = -1;
        this.dialogVisible = true;
      },handleClose(){
        this.dialogVisible = false;
      },sumbmitHandle(){
        var _this=this;
        this.axios({
          url: 'http://127.0.0.1:3000/dataDict/add',
          method: 'get',
          params:{
           /* id1:this.dataDict.id1,*/
            id: this.dataDict.id,
            display:this.dataDict.display,
            type:this.dataDict.type,
            desc:this.dataDict.desc

          }
        }).then(function (res) {
          if (res.data.flag){
            _this.tableData=res.data.dat;
            _this.$message('操作成功')
            _this.dialogVisible = false;
          }else {
            alert('操作失败');
          }

        })
      },handleDoubleClick(row){
       // alert(row.id1);
        this.dataDict=row;
        this.info.title='员工修改';
        this.dialogVisible =true;
      }
    }
  }
</script>

<style scoped>
  .el-dropdown-link {
    cursor: pointer;
    color: #409EFF;
  }
  .el-icon-arrow-down {
    font-size: 12px;
  }

</style>
